package com.demo.springboot;

import com.demo.corebean.Role;
import com.demo.corebean.User;
import com.demo.corebean.UserConfig;
import com.google.gson.Gson;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;

/**
 * @EnableAutoConfiguration 作用：从ClassPath中搜索所有META-INF/spring.factories配置文件
 * 然后，将其中org.springframework.boot.autoconfigure.EnableAutoConfiguration key
 * 对应的配置项加载到spring容器
 *
 * 内部实现关键点：
 * 1.ImportSelector 该接口的实现方法的返回值都会被纳入到spring容器管理中
 * 2.SpringFactoriesLoader 该类可以从classpath中搜索所有META-INF/spring.factories配置文件，病毒去配置
 *
 * @EnableAutoConfiguration 还可以进行排除
 * 1.exclude 根据类(Class)来排除
 * 2.excludeName 根据类名来排除
 *
 * 只有 spring.boot.enableautoconfiguration为true时，才会启用自动配置，默认是true
 */
@EnableAutoConfiguration
@ComponentScan
public class App {
    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(App.class, args);
        System.out.println("Runnable:"+context.getBean(Runnable.class));
        System.out.println("Role:"+context.getBean(Role.class));
        System.out.println("User:"+context.getBean(User.class));
        System.out.println("Gson:"+context.getBean(Gson.class));

        context.close();
    }
}
